package com.smec.remes.module.submit.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;

import com.hwangjr.rxbus.annotation.Subscribe;
import com.hwangjr.rxbus.annotation.Tag;
import com.hwangjr.rxbus.thread.EventThread;
import com.smec.moblie.R;
import com.smec.moblie.databinding.ActivityApproveLogBinding;
import com.smec.remes.base.SmecBaseActivity;
import com.smec.remes.bean.SmecLogBean;
import com.smec.remes.module.submit.SmecSubmitPresenter;
import com.smec.remes.module.submit.adapter.SmecLogAdapter;
import com.smec.remes.util.CommonUtils;
import com.smec.remes.util.TopBarLayout;

import java.util.ArrayList;

/**
 * Created by xupeizuo on 2018/2/28.
 */

public class SmecLogActivity extends SmecBaseActivity<SmecSubmitPresenter> {

    private ActivityApproveLogBinding activityApproveLogBinding;
    private String applyOrderNo;
    public static final String GET_LOG_SUCCESS="GET_LOG_SUCCESS";
    private SmecLogAdapter adapter;

    @Override
    public SmecSubmitPresenter getPresenter() {
        return new SmecSubmitPresenter(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityApproveLogBinding=DataBindingUtil.setContentView(this, R.layout.activity_approve_log);
        getDataFromIntent();
        initView();
    }

    private void getDataFromIntent(){
        applyOrderNo=this.getIntent().getStringExtra("applyOrderNo");
        mPresenter.getLog(applyOrderNo);
    }

    private void initView(){
        activityApproveLogBinding.searchTopbar.setTopBarListener(new TopBarLayout.TopBarListener() {
            @Override
            public void setOnLeftClickListener() {
                finish();
            }

            @Override
            public void setOnRight1ClickListener() {

            }

            @Override
            public void setOnRight2ClickListener() {

            }
        });
        adapter=new SmecLogAdapter(this);
        activityApproveLogBinding.listRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        activityApproveLogBinding.listRecyclerView.setAdapter(adapter);
    }

    @Subscribe(
            thread = EventThread.MAIN_THREAD,
            tags = {
                    @Tag(GET_LOG_SUCCESS)
            }
    )

    public void _detailsSuccess(ArrayList<SmecLogBean> arrayList){
        if(CommonUtils.notEmpty(arrayList)) {
            adapter.setArrayList(arrayList);
        }
    }

}
